package work.easy.monitor;

import com.alibaba.fastjson.JSON;


import java.util.*;

public class AlarmDemo {
    public static void main(String[] args) throws Exception {
        //AlarmParam param = new AlarmParam();
        Map<String,Object> param = new HashMap<>();

        Long clientId = 4L;
        String appKey = "OGJiMzg4N2YtZDMyNy00MjVkLWFlYWYtMTA4MDI0NDZlNzhh";
        String secret = "0iEmsLWTgz+6MTr9ws4bzQ==";
        param.put("clientId",clientId);//稍后提供
        Map<String, Map<String, Object>> typeAuth = new HashMap<>();

        Map<String, Object> type2 = new HashMap<>();
        type2.put("from", "xxxx业务线报警");
        typeAuth.put("2", type2);

        //Map<String, Object> type3 = new HashMap<>();
        //type3.put("agentid", "1000002");
        //type3.put("corpid", "wx69d6075aadc53b09");
        //type3.put("corpsecret", "_JBKhZw5A9aLJPnhye_lpxyW9_inLEPpcEFlFy4Qe1c");
        //typeAuth.put("3", type3);

        //Map<String, Object> type4 = new HashMap<>();
        //type4.put("access_token", "017ee37a7323c3649e8a593b785b985dbe72cd0e5570dbf0a48fabebca99d9fc");
        //typeAuth.put("4", type4);

        //List<AlarmParam.Message> messages = new ArrayList<>();
        List<Map<String,Object>> messages = new ArrayList<>();
        Map<String,Object> message = new HashMap<>();
        //message.setMessage("报警啦");
        message.put("message","报警内容");

        //message.setToUserIds(Arrays.asList(1, 2));
        message.put("toUserIds",Arrays.asList(1, 2));
        Map<String, List<String>> toUsers = new HashMap<>();
        toUsers.put("1",Arrays.asList("15011527023"));
        toUsers.put("2",Arrays.asList("name@domain","name2@domain2"));
        //toUsers.put("3",Arrays.asList("yuexiao","liutao3"));
        //toUsers.put("4",Arrays.asList("15011527023","15737756535"));
        //toUsers.put("5", Arrays.asList("15011527023","15737756535"));
        //message.setToUsers(toUsers);
        message.put("toUsers",toUsers);
        messages.add(message);
        //param.setMessages(messages);
        param.put("messages",messages);

        String json = JSON.toJSONString(typeAuth);

        String sign = MD5Utils.md5toHex(appKey + json);
        param.put("sign",sign);

        byte[] encrypt =  CryptoUtil.encrypt("AES", secret,json);

        param.put("typeAuths",Base64.getEncoder().encodeToString(encrypt));
        String url = "http://10.152.16.27:18001/api/v1/monitor/alarm/sendMessage";
        Map map = HttpUtils.postObjectFor(url, param, Map.class);
        //Map map = HttpUtils.postObjectFor("http://10.143.88.66/api/v1/monitor/alarm/sendMessage", param, Map.class);
        //Map map = HttpUtils.postObjectFor("http://10.143.108.25:8001/api/v1/monitor/alarm/sendMessage", param, Map.class);
        System.out.println("RESULT:" + map);
    }
}
